<?php
	include("event-config.php");

	$name = 		$_POST['name'];
	$start_date = 	$_POST["startDate"];
	$end_date = 	$_POST["endDate"];
	$benefit = 		$_POST["benefit"];
	$description = 	$_POST["description"];
	$slot = 		$_POST["slot"];
	$date = 		date('Y-m-d H:i:s');

	$query = "INSERT INTO $EVENT(`name`, `start_date`, `end_date`, `benefit`, `description`, `slot`, `post_date`) 
			             VALUES ('$name', '$start_date', '$end_date', '$benefit', '$description', '$slot', '$date')";
	
	if(!execute($query)){
		echo "fail";
	}
	else{
		//get the event id
		$query = "SELECT `event_id` FROM $EVENT WHERE `post_date` = '$date'";
		$event_id = first_row($query);
		$event_id = $event_id['event_id'];
		//Get the question
		if (isset($_POST['question']) && $_POST['question'] != "") {
			$question =	$_POST["question"];
			$type 	  = $_POST["type"];

			if (isset($_POST['answer']) && $_POST['answer'] != "") {
				//add question
				$answer = $_POST["answer"];
				if(!add_question($event_id, $question, $type, $answer))
					die("Khong add dc poll");
			}
			else{
				die("Khong co cau tra loi");
			}
		}
		echo $event_id;
	}
?>